package com.example.controller;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.param.StudentRequest;
import com.example.service.StudentService;
import com.example.vo.StudentVO;

@RestController
@RequestMapping("/test")
public class StudentController {

	@Autowired
	private StudentService studentService;
	
	@Autowired
	private RedisTemplate<String,Object> redisTemplate;

	/**
	 * 添加学生信息
	 * 
	 * @param studentRequest
	 * @return
	 */
	@RequestMapping(value = "/add", consumes = MediaType.APPLICATION_JSON_VALUE)
	public int add(@RequestBody StudentRequest studentRequest) {
		return studentService.addStudent(studentRequest);
	}

	/**
	 * 删除学生信息
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping(value = "/delete", consumes = MediaType.APPLICATION_JSON_VALUE)
	public int delete(@RequestBody Set<Integer> ids) {
		return studentService.deleteStudent(ids);
	}

	/**
	 * 修改学生信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "/update", consumes = MediaType.APPLICATION_JSON_VALUE)
	public int update(@RequestBody StudentRequest studentRequest) {
		return studentService.updateStudent(studentRequest);
	}

	/**
	 * 查询学生信息
	 * 
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/query")
	public StudentVO queryById(Integer id) {
		return studentService.queryById(id);
	}
	
	@GetMapping(value = "/all")
	public Object queryAll() {
		 Object object1=redisTemplate.boundValueOps("redis_1").get();
		return object1;
	}
}
